package com.example.demo1;



public class Cake {
    private static final long serialVersionUID = 1L;
    private String id;
    private String name;
    private int price;
    private int num;

    public Cake() {
    }
    public Cake(String id,String name,int price,int num){
        this.id = id;
        this.name = name;
        this.price = price;
        this.num = num;
    }
    public String getId(){

        return id;
    }
    public void setId(String id){

        this.id = id;
    }
    public String getName(){

        return name;
    }
    public void setName(String name){

        this.name = name;
    }
    public int getPrice(){

        return price;
    }
    public void setPrice(int price){

        this.price = price;
    }
    public int getNum(){

        return num;
    }
    public void setNum(int num){

        this.num = num;
    }
    public void addStock(int count) {
        this.num += count;
    }

    public void reduceStock(int count) {
        if (this.num >= count) {
            this.num -= count;
        } else {
            throw new IllegalArgumentException("库存不足，无法购买");
        }
    }

    public int getStock() {
        return this.num;
    }

}